package com.itheima.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.UserMapper;
import com.itheima.daomain.User;
import com.itheima.util.SessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * @Descriptionn:test
 * @Create by:依然
 * @Date:2021/11/2 16:31
 */
public class UserService {
    public PageInfo<User> queryAllUserServlet() {
        SqlSession sqlSession = SessionFactoryUtils.getSession();
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);

        List<User> users = userMapper.SelectAll();
        PageInfo<User> pageInfo = new PageInfo<>(users);
        sqlSession.close();
        return pageInfo;
    }
    public PageInfo<User> pageUser(int currentPage) {


        PageHelper.startPage(currentPage, 5);



        SqlSession sqlSession = SessionFactoryUtils.getSession();
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        List<User> userList = userMapper.SelectAll();

        PageInfo<User> pageInfo = new PageInfo<>(userList);


        return pageInfo;
    }


}
